package com.dep.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dep.domain.MockDTO;
import com.dep.domain.New;
import com.dep.domain.Person;
import com.dep.service.MessagePush;
/**
 * 推送Controller
 * @author xiaoyou11@hotmail.com
 *
 */
@Controller
@RequestMapping("/push")
public class PushMessageController {
	
	@Autowired
	private MessagePush messagePush;

	
	/****
	 * 		这个方法模拟几条数据，用来接收webservice接口或其他调用过来的数据
			 * p的格式需要与接口方确认
			 * p的格式 : 		{type:"person",		entity:[{name:"zhangsan",age:14},{name:"lisi",age:25}]}
			 * 				{type:"new"   ,		entity:[{title:"title1",content:"content1....."},{title:"title2",content:"content2....."}]}
			 * @param p
			 * @return
	 */
	@RequestMapping(value = "/send", method = RequestMethod.GET)
	@ResponseBody		//因为ClassPath上用的是jackson，所以这里会转换为JSON格式的返回值
	public String sendMessageAuto( ){
		
		//模拟第一条记录
		List<Person> pList = new ArrayList<Person>();
		for(int i=0;i<3;i++){
			Person p = new Person();
			p.setAge(14+i);
			p.setName("__小"+i);
			pList.add(p);
		}
		MockDTO  mock_1 = new MockDTO();
		mock_1.setType("person");
		mock_1.setObj(pList);
		
		//模拟第二条记录
		List<New> nList = new ArrayList<New>();
		for(int j=0;j<2;j++){
			New n = new New();
			n.setTitle("会议日程__("+j+")");
			n.setContent("("+j+")___党十九大会议即将召开........");
			nList.add(n);
		}
		MockDTO  mock_2 = new MockDTO();
		mock_2.setType("news");
		mock_2.setObj(nList);
		
		messagePush.sendMessageAuto(mock_1);
		messagePush.sendMessageAuto(mock_2);
		
		//messagePush.sendMessageAuto(post);
		return "{success:true}";
		
	}
}
